/*
 * OPIAM Suite
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */

package opiam.admin.faare.config.javabeans;

import java.io.Serializable;

import java.util.HashMap;
import java.util.Map;


/**
 * Class corresponding to the "viewdef_profiles" element of views.xml.<br>
 * This is a list of profiles which can see a view.
 */
public class JBViewDefProfiles implements Serializable
{
    /** Profiles table, key = lower case profile name. */
    private Map viewDefProfileMap = new HashMap();

    /** Creates new JBViewDefs. */
    public JBViewDefProfiles()
    {
    }

    /**
     * Returns the list of profiles.
     * @return List of JBViewDefProfile
     */
    public Map getViewDefProfileList()
    {
        return viewDefProfileMap;
    }

    /**
     * Adds a profile to the list.
     *
     * @param v profile to add
     */
    public void addViewDefProfile(JBViewDefProfile v)
    {
        this.viewDefProfileMap.put(v.getName().trim().toLowerCase(), v);
    }

    /**
     * Gets a profile from its name.
     * ASSERT : name should not be null
     *
     * @param name profile name
     *
     * @return JBViewDefProfile object
     */
    public JBViewDefProfile findViewDefProfileByName(String name)
    {
        // rendre case insensitive en mettant le param en lowercase
        String key = name.trim().toLowerCase();

        return (JBViewDefProfile) viewDefProfileMap.get(key);
    }

    /**
     * see Object.toString().
     *
     * @return Object.toString()
     */
    @Override
	public String toString()
    {
        StringBuffer buf = new StringBuffer();
        java.util.Iterator it = null;

        if (viewDefProfileMap != null)
        {
            buf.append("Map components of viewDefMap = ");
            buf.append(System.getProperty("line.separator"));
            it = viewDefProfileMap.values().iterator();

            while (it.hasNext())
            {
                buf.append(".");
                buf.append(it.next());
                buf.append(System.getProperty("line.separator"));
            }
        }

        return buf.toString();
    }

    // end of toString method
}
